Receiving High-Level Events
Receiving High-Level Events
In System 7.0+, your application can receive a high-level event when it
retrieves an event from the Event Manager. As always, your application
determines what kind of event it has received by looking at the what field of the
EventRecord returned by the Event Manager. The event code for high-level
events is defined by a constant name.
kHighLevelEvent
For high-level events, two fields of the EventRecord have special meanings.
The message field and the where field of the EventRecord together define the
specific type of high-level event and are interpreted as type OSType, not long
or Ptr. The message field contains the event class of this high-level event. For
example, Apple events sent by the Edition Managerhave the event class
called 'sect'. You can define your own class of events that are specific to your
application. If you have registered your application signature, then you can use
your signature to define the class of events that belong to your application.
Note, however, that Apple reserves all lowercase letters and nonalphabetic
characters for the classes of events defined by Apple.
For high-level events, the where field in the EventRecord contains a second
message specifier, called the eventID. The eventID defines the particular type
of event (or message) within the class of events defined by the
event class. For example, the SectionReadApple event sent by the
Edition Manager has EventClass 'sect' and eventID 'read'. The
OpenDocumentsApple event sent by the Finder has event class 'aevt' and
eventID 'odoc'. You can define your own set of eventIDs, corresponding to your
own event class. For example, if the message field contains 'boff' and the where
field contains 'cmd1', then the high-level event indicates the type of event
defined by 'cmd1' within the class of events defined by the application with the
signature 'boff'.
Unlike low-level events and operating-system events,
high-level events may not be completely determined by the EventRecord
returned to your application when it calls WaitNextEvent. For example, you
might still need to know which other application sent you the
high-level event or what additional data that application wants to send you.
This further information about the high-level event is available to your
application by calling the AcceptHighLevelEvent function. The additional
information associated with a high-level event includes:
the identity of the sender of the event
unique EventID number that identifies this particular event
• the address and length of a data buffer that can contain optional data
To obtain this additional information, your application must call
AcceptHighLevelEvent before calling WaitNextEvent again. By
convention, calling AcceptHighLevelEvent indicates that your application
intends to process the high-level event.
Note: Because the where field of an EventRecord for a high-level event is used to
select a specific kind of event (within the class determined by the message
field), high-level event records do not contain the mouse position at the
time of the event. Moreover, it is dangerous to interpret the where field
before interpreting the what field because different event classes can
contain overlapping sets of eventIDs.